﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace NapCardOnline.Models
{
    public partial class CommissionLevel
    {
        private static NapCardOnlineEntities DBEntities = new NapCardOnlineEntities();

        /// <summary>
        /// Gets the commission by user ID.
        /// </summary>
        /// <param name="userId">The user id.</param>
        /// <returns>Commission percent</returns>
        public static double? GetTransferFundCommissionByUserID(int userId)
        {
            double? commision = 0;
            User objUser = DBEntities.Users.FirstOrDefault(u => u.UserID == userId);
            if (objUser != null)
            {
                var objCommision = DBEntities.CommissionLevels.FirstOrDefault(c => c.CommissionLevelID == objUser.FK_CommissionLevelID);
                if (objCommision != null)
                {
                    commision = objCommision.CommissionPercent;
                }
            }
            return commision;
        }

        /// <summary>
        /// Gets the commission level by user id.
        /// </summary>
        /// <param name="userId">The user id.</param>
        /// <returns></returns>
        public static int GetCommissionLevelIdByUserId(int userId)
        {
            User objUser = DBEntities.Users.FirstOrDefault(u => u.UserID == userId);
            if (objUser != null)
            {
                var objCommisionLevel = DBEntities.CommissionLevels.FirstOrDefault(c => c.CommissionLevelID == objUser.FK_CommissionLevelID);
                if (objCommisionLevel != null)
                {
                    return objCommisionLevel.CommissionLevelID;
                }
            }
            return 0;
        }
    }
}